<?php

namespace app\admin\model\game;

use think\Model;


class Prize extends Model
{

    

    

    // 表名
    protected $name = 'game_prize';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text'
    ];
    

    
    public function getTypeList()
    {
        return ['0' => __('Type 0'), '1' => __('Type 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAll(){

        $res = $this->where("ratio",">","0")->select();
        return $res;
    }

    
    public function updateNumById($id){
        $res = $this->where("id",$id)->inc('num')->inc('dayNum')->update();;
        return $res;
    }


    public function getPrizeById($prize_id)
    {
         $res = $this->field("name,type,url")->where("prizeId","=",$prize_id)->find();
        return $res;
    }



    public function initDay()
    {
        $update_data = ["dayNum" => 0];
        $res = $this->where("id",">",0)->update($update_data);
        return $res;
    }

}
